package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.domain.Travel;
import cn.wolfcode.luowowo.query.TravelQuery;
import cn.wolfcode.luowowo.service.ITravelService;
import cn.wolfcode.luowowo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//旅游日记控制器
@Controller
@RequestMapping("travel")
public class TravelController {
    //注入旅游日记业务
    @Autowired
    private ITravelService travelService;

    //旅游日记分页查询
    @RequestMapping("/list")
    public String list(Model model , @ModelAttribute("qo") TravelQuery qo){
        //Page是spring-data-mongodb 里封装分页参数的对象.类似pegeinfo
        Page<Travel> page = travelService.list(qo);
        model.addAttribute("page" , page);
        return "travel/list";
    }

    //查看单个游记内容
    @RequestMapping("/getContentById")
    @ResponseBody
    public Object getContentById(String id){
        Travel travel = travelService.get(id);
        //返回游记内容结果
        return JsonResult.success(travel.getContent());
    }

    //修改状态
    @RequestMapping("/changeState")
    @ResponseBody
    public Object changeState(String id , int state){
        travelService.changeState(id,state);
        //返回结果
        return JsonResult.success();
    }


}
